<?php
class C_prestasi extends Nvl_Controller{
	
	function __construct(){
		parent::__construct();
		session_start();
		/* if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
			if(!isset($_SESSION[SESSION_USERID])){
				$this->output->set_status_header('301');
			}
		}else{
			if(!isset($_SESSION[SESSION_USERID])){
				$this->session->set_flashdata("Sesi anda telah berakhir. Silahkan login ulang.");
				redirect('c_login');
			}
		} */
		$this->load->model('m_prestasi');
	}
	
	function index(){
		$this->load->view('pages/v_prestasi');
	}
	
	function data_list(){
		$searchText = $this->input->post('searchText');
		$start = $this->input->numeric('start','get');
		$end = $this->input->numeric('page_size','get');
		$result = $this->m_prestasi->data_list($searchText, $start, $end);
		echo $result;
	}
	
	function create(){
		$params = array(
			"foto"=>$this->input->post('foto'),
			"id_sekolah"=>$this->input->post('id_sekolah'),
			"id_semester"=>$this->input->post('id_semester'),
			"kompetisi"=>$this->input->post('kompetisi'),
			"nama_siswa"=>$this->input->post('nama_siswa'),
			"nis"=>$this->input->post('nis'),
			"peringkat"=>$this->input->post('peringkat'),
			"tahun_ajar"=>$this->input->post('tahun_ajar')
		);
		$result = $this->m_prestasi->__save($params);
		echo $result;
	}
	
	function update(){
		$id_prestasi = $this->input->numeric('id_prestasi');
		$params = array(
			"foto"=>$this->input->post('foto'),
			"id_sekolah"=>$this->input->post('id_sekolah'),
			"id_semester"=>$this->input->post('id_semester'),
			"kompetisi"=>$this->input->post('kompetisi'),
			"nama_siswa"=>$this->input->post('nama_siswa'),
			"nis"=>$this->input->post('nis'),
			"peringkat"=>$this->input->post('peringkat'),
			"tahun_ajar"=>$this->input->post('tahun_ajar')
		);
		$result = $this->m_prestasi->__save($params, $id_prestasi);
		echo $result;
	}
	
	function delete(){
		$id_prestasi = $this->input->numeric('id_prestasi');
		$result = $this->m_prestasi->__delete($id_prestasi);
		echo $result;
	}
	
	function search(){
		$query = $this->input->post('query');
		$result = $this->m_prestasi->search($query);
		echo $result;
	}
}